package com.yixing.tech.datasync.task;

import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.datasync.service.InStockSyncService;
import com.yixing.tech.datasync.service.StockOutSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * @author yixing tech
 * @since 1.0.0
 */
@Slf4j
@Component
public class DataSyncTask {

    @Autowired
    private InStockSyncService rawInStockSyncService;

    @Resource
    private StockOutSyncService stockOutSyncService;

    // 1分钟一次
    @Scheduled(fixedDelay = 1 * 60 * 1000)
    public void syncRawInStock() {
        try {
            rawInStockSyncService.syncRawInStock();
        } catch (BusinessException e) {
            log.error("同步失败: ", e);
        }
    }

    @Scheduled(fixedDelay = 1 * 60 * 1000)
    public void syncProductionInStock() {
        try {
            rawInStockSyncService.syncProductionInStock();
        } catch (BusinessException e) {
            log.error("同步失败: ", e);
        }
    }

//    @Scheduled(fixedDelay = 1 * 60 * 1000)
    public void syncSalesReturnStock() {
        try {
            rawInStockSyncService.syncSalesReturnStock();
        } catch (BusinessException e) {
            log.error("同步失败: ", e);
        }
    }

    @Scheduled(fixedDelay = 1 * 60 * 1000)
    public void syncBillProdPick() {
        try {
            stockOutSyncService.syncBillProdPick();
        }catch (Exception ex) {
            log.error("同步领料出库单抛出异常:{}", ex);
        }
    }

    @Scheduled(fixedDelay = 1 * 60 * 1000)
    public void syncBillSalesOutStock() {
        try {
            stockOutSyncService.syncBillSalesOutStock();
        }catch (Exception ex) {
            log.error("同步销售出库单抛出异常:{}", ex);
        }
    }

    @Scheduled(fixedDelay = 1 * 60 * 1000)
    public void syncBillSalesPackOutStock() {
        try {
            stockOutSyncService.syncBillSalesPackOutStock();
        }catch (Exception ex) {
            log.error("同步销售打包出库单抛出异常:{}", ex);
        }
    }
}
